const baseURL = "http://127.0.0.1:3000";
export interface ResponseBody<T = any> {
  code: number;
  success: boolean;
  message: string;
  result: T;
}
export const request = <T extends ResponseBody>(options: any): Promise<T> => {
  return new Promise((resolve, reject) => {
    uni
      .request({
        url: baseURL + options.url,
        method: options.method || "GET",
        data: options.data || {},
        header: {
          openid: uni.getStorageSync("user")?.openid,
        },
      })
      .then(({ data }) => {
        resolve(data as T);
      })
      .finally(() => console.log("请求完成"))
      .catch(reject);
  });
};
